
<template src="./tpl.html"></template>

<script>
import { CONSENT_GET_NJ_SQDSJ, CONSENT_GET_FKLC_SQDSJ, CONSENT_GET_MZK_PATIENT_LIST } from "_SERVICES/api";
import { trimAll } from "UTILS/string";
import { isvalidateNum2 } from "UTILS/validate";
import { timeFormatter, getDay } from "UTILS/format";
import { getStorage, setStorage } from "UTILS/util";


// 20241016 zly改成了内镜、妇科共用这个页面 （原来的内镜申请单页面）
import page from "@/modules/CST/mxins/page";
export default {
  name: "mzmz_list",
  mixins: [page],
  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      formInline: {
        KDSJ: [getDay(-120, 1), timeFormatter(new Date(), 2)],
        ZYH: "",
        BRBH: "",
        BRXM: "",
        SEARCH_TYPE: "NJ_SQD"
      },
      card_obj: {},

      headers: [
        {
          label: "ID",
          prop: "REPORTSNO",
          width: 100
        },
        {
          label: "就诊卡号",
          prop: "BRBH",
        },
        {
          label: "住院号",
          prop: "ZYH",
          width: 80
        },
        {
          label: "体检编号",
          prop: "TJBH",
          width: 100
        },
        {
          label: "患者姓名",
          prop: "BRXM",
          width: 100
        },
        {
          label: "性别",
          prop: "BRXB_STR",
          width: 60
        },
        {
          label: "联系方式",
          prop: "LXDH",
          width: 100
        },
        {
          label: "诊疗类型",
          prop: "ZLLX_STR",
          width: 70
        },
        {
          label: "检查项目",
          prop: "JCXM",
        },
        {
          label: "开单科室",
          prop: "SJKS",
        },
        {
          label: "开单时间",
          prop: "KDSJ_STR",
        },
        {
          label: "状态",
          prop: "ZTBZ_STR",
          width: 70
        },
      ],
      tableData2: [],
      headers2: [
        {
          label: "ID",
          prop: "REPORTSNO",
        }, {
          label: "诊疗类型",
          prop: "ZLLX_STR",
        }, {
          label: "就诊卡号",
          prop: "BRBH",
        }, {
          label: "住院号",
          prop: "ZYH",
        }, {
          label: "患者姓名",
          prop: "BRXM",
        },
        {
          label: "性别",
          prop: "BRXB_STR",
          width: 60
        },
        {
          label: "联系方式",
          prop: "LXDH",
        }, {
          label: "就诊/住院科室",
          prop: "SJKS",
        },
        {
          label: "就诊时间",
          prop: "JZSJ_STR",
        }
      ]
    };
  },
  created() {
    if (this.$route.query && this.$route.query.BRBH) {
      this.formInline.BRBH = this.$route.query.BRBH
    } else {
      // if (getStorage("njsqd_list_params")) {
      //   let info = JSON.parse(getStorage("njsqd_list_params"))
      //   this.formInline = info;
      //   if(!this.formInline.TYPE) { //新增的字段，怕没有
      //     this.formInline.TYPE = 'NJ_SQD'
      //   }
      // }
    }
    // this.getList();

  },
  beforeDestroy() {
    // setStorage({
    //   name: "njsqd_list_params",
    //   value: JSON.stringify(this.formInline),
    // });
  },

  mounted() { },
  methods: {
   
    resetForm(name) {

      this.formInline = {
        KDSJ: [getDay(-120, 1), timeFormatter(new Date(), 2)],
        ZYH: "",
        BRBH: "",
        BRXM: "",
        SEARCH_TYPE: "NJ_SQD"
      },
      this.$refs.ybCard.clear();
      this.card_obj = {}
      this.tableData = []
      this.tableData2 = []
    },

    //不带刷卡数据
    search_2() {
      this.$refs.ybCard.clear();
      this.card_obj = {}
      this.search()
    },

    getList() {

      let params = {
        ...this.formInline,
        BSLX: this.card_obj.BSLX || "",//BSLX
        WYBS: this.card_obj.WYBS || "",//WYBS
      };    

      if (params.WYBS) {
        params = {
          KDSJ: params.KDSJ,
          BSLX: params.BSLX,
          WYBS: params.WYBS,
          insuplc_admdvs:this.card_obj.insuplc_admdvs
        }
      } else {

        if (!params.BRXM && !params.BRBH && !params.ZYH) {
          this.$message.warning("请输入患者信息进行查询");
          return false;
        }
      }

      this.listLoading = true;

      // Object.assign(params, this.getParams());

      if (this.formInline.SEARCH_TYPE == 'NJ_SQD') {
        return CONSENT_GET_NJ_SQDSJ(params)
          .then((res) => {
            this.listLoading = false;
            this.listQuery.totalNum = res.data.totalNum;

            res.data.list.forEach(item => {
              item.SEARCH_TYPE = this.formInline.SEARCH_TYPE;  // 新增字段
            });
            this.tableData = res.data.list;
            this.setBrbh(res.data.patientInfo)
            this.getMzList(params);
            this.CONSENT_GET_CURRENT_VERSION();//检查版本
          })
          .catch((res) => {
            this.listLoading = false;
            this.downloadLoading = false;
        });
      } else if (this.formInline.SEARCH_TYPE == 'FKLC_ZLYZ') {
        return CONSENT_GET_FKLC_SQDSJ(params)
          .then((res) => {
            this.listLoading = false;
            this.listQuery.totalNum = res.data.totalNum;
            res.data.list.forEach(item => {
              item.SEARCH_TYPE = this.formInline.SEARCH_TYPE;  // 新增字段
            });
            this.tableData = res.data.list;
            this.setBrbh(res.data.patientInfo)
            this.getMzList(params);

            this.CONSENT_GET_CURRENT_VERSION();//检查版本
          })
          .catch((res) => {
            this.listLoading = false;
            this.downloadLoading = false;
        });
      }

    },
    getMzList(params) {
      if (params.WYBS) { //刷卡的情况下，如果是医保电子凭证不能二次使用
        CONSENT_GET_MZK_PATIENT_LIST({
          BRBH: this.formInline.BRBH,
          ZYH: this.formInline.ZYH,
          BRXM: this.formInline.BRXM
        }).then((res) => {
          this.tableData2 = res.data.list || []
        })
      } else {
        CONSENT_GET_MZK_PATIENT_LIST(params).then((res) => {
          this.tableData2 = res.data.list || []
        })
      }

    },
    //刷卡只受预约时间的约束
    back(obj) {
      if (obj.code == 0) {
        this.card_obj = obj;
        this.search();
      } else {
        this.card_obj = {}
        if (obj.msg) {
          this.$message.error(obj.msg)
        }
      }

    },
    rowClick(row) {
      let baseUrl = `http://localhost:9527/CST.html#/consentList?`;
      if (process.env.VUE_APP_build_type == 'production') {
        baseUrl = `http://10.1.6.124:99/CST.html#/consentList?`;
      }
      baseUrl += `fromPage=PATIENT_LIST&BRBH=${row.BRBH}&BRXM=${row.BRXM}&GET_PATIENT_BY_PRIMARY=${row.REPORTSNO}&GET_PATIENT_TYPE=${row.SEARCH_TYPE}`
      window.open(baseUrl, '_blank');
    },
    rowClick2(row) {
      let baseUrl = `http://localhost:9527/CST.html#/consentList?`;
      if (process.env.VUE_APP_build_type == 'production') {
        baseUrl = `http://10.1.6.124:99/CST.html#/consentList?`;
      }
      baseUrl += `fromPage=PATIENT_LIST&BRBH=${row.BRBH}&BRXM=${row.BRXM}&GET_PATIENT_BY_PRIMARY=${row.REPORTSNO}&GET_PATIENT_TYPE=MZMZ_LIST`
      window.open(baseUrl, '_blank');
    }
  },
};
</script>

<style lang="less">
.table2_header_class {
  background: #66b1ff !important;
  color: #fff !important;
}
</style>
